import sys
file = open("input.txt")
data = file.readlines()
N = int(data[0])
box = [0] + list(map(int, data[1].split()))
gas = [0] + [1] + [1000000] * (N - 1)
for i in range(N, 0, -1):
    j = i - 1
    while j > 0 and box[j] != box[i]:
        j -= 1
    if box[j] == box[i]:
        gas[i] = j
i = N
j = N
ans = 0
planets = []
while i > 1:
    visited = set()
    starts = []
    for t in range(i, j + 1):
        if box[t] not in visited:
            visited.add(box[t])
            starts += [gas[t]]
    j = i - 1
    if starts == []:
        print(0)
        sys.exit()        
    i = min(starts)
    ans += 1
    planets += [i]
print(ans)
print(' '.join(map(str, planets[::-1])))
